﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Urb.Weather.Yahoo
{
    public enum YahooWeatherConditionCode : short
    {
        Code_00_tornado = 0,
        Code_01_tropical_storm = 1,
        Code_02_hurricane = 2,
        Code_03_severe_thunderstorms = 3,
        Code_04_thunderstorms = 4,
        Code_05_mixed_rain_and_snow = 5,
        Code_06_mixed_rain_and_sleet = 6,
        Code_07_mixed_snow_and_sleet = 7,
        Code_08_freezing_drizzle = 8,
        Code_09_drizzle = 9,
        Code_10_freezing_rain = 10,
        Code_11_showers = 11,
        Code_12_showers = 12,
        Code_13_snow_flurries = 13,
        Code_14_light_snow_showers = 14,
        Code_15_blowing_snow = 15,
        Code_16_snow = 16,
        Code_17_hail = 17,
        Code_18_sleet = 18,
        Code_19_dust = 19,
        Code_20_foggy = 20,
        Code_21_haze = 21,
        Code_22_smoky = 22,
        Code_23_blustery = 23,
        Code_24_windy = 24,
        Code_25_cold = 25,
        Code_26_cloudy = 26,
        Code_27_mostly_cloudy_night = 27,
        Code_28_mostly_cloudy_day = 28,
        Code_29_partly_cloudy_night = 29,
        Code_30_partly_cloudy_day = 30,
        Code_31_clear_night = 31,
        Code_32_sunny = 32,
        Code_33_fair_night = 33,
        Code_34_fair_day = 34,
        Code_35_mixed_rain_and_hail = 35,
        Code_36_hot = 36,
        Code_37_isolated_thunderstorms = 37,
        Code_38_scattered_thunderstorms = 38,
        Code_39_scattered_thunderstorms = 39,
        Code_40_scattered_showers = 40,
        Code_41_heavy_snow = 41,
        Code_42_scattered_snow_showers = 42,
        Code_43_heavy_snow = 43,
        Code_44_partly_cloudy = 44,
        Code_45_thundershowers = 45,
        Code_46_snow_showers = 46,
        Code_47_isolated_thundershowers = 47,
        Code_3200_not_available = 3200,
    }

    public static class YahooWeatherConditionCodeUtils
    {
        public static YahooWeatherConditionCode? ConvertToYahooWeatherConditionCode(this string value)
        {
            if (string.IsNullOrWhiteSpace(value))
                return null;

            short result;

            if (short.TryParse(value.Trim(), out result))
            {
                if (Enum.IsDefined(typeof(YahooWeatherConditionCode), result))
                    return (YahooWeatherConditionCode)result;
            }

            return null;
        }
    }
}
